package main

func prefix(str1 string, str2 string) string {
	if len(str1) == 0 {
		return ""
	}
	var prefix string
	var shorter string
	if len(str1) < len(str2) {
		prefix = str2
		shorter = str1
	} else {
		prefix = str1
		shorter = str2
	}

	for i, c := range shorter {
		if prefix[i] != uint8(c) {
			return prefix[:i]
		}
	}
	return prefix[:len(shorter)]
}

func longestCommonPrefix(strs []string) string {
	if strs == nil || len(strs) == 0 {
		return ""
	}
	result := strs[0]
	for _, s := range strs {
		result = prefix(result, s)
	}
	return result
}

func main() {
	strs := []string{"aaa", "aa", "aaa"}
	println(longestCommonPrefix(strs))
	//println(prefix("aa", "aaa"))
}
